﻿/********************************************************************************
     File:																
            Manager.aspx.cs                         
     Description:
            分类信息管理
     Author:									
            DDBuildTools
            http://DDBuildTools.supesoft.com
     Finish DateTime:
            2011-7-28 16:36:37
     History:
*********************************************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using BingZi.HY.Core.Entities.Center;
using BingZi.HY.Core.Enums;
using BingZi.HY.Core.Message;
using BingZi.HY.Core;
using BingZi.HY.Core.WebControls;





namespace BingZi.HY.UI.Center.Manager.app_CategoryUI
{
    public partial class Manager : BingZi.HY.Core.BLL.PageBase
    {
        Int32 IDX = (Int32)BingZi.HY.Core.Common.sink("IDX", BingZi.HY.Core.Enums.MethodType.Get, 10, 0, DataType.Int);
        string CMD = (string)BingZi.HY.Core.Common.sink("CMD", BingZi.HY.Core.Enums.MethodType.Get, 10, 1, DataType.Str);
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckPagePermission(CMD);
            if (!Page.IsPostBack)
            {
                OnStart();
            }
        }
        
        /// <summary>
        /// 开始操作
        /// </summary>
        private void OnStart()
        {
            app_Category ut = app_Category.FindByKeyForEdit(IDX);
            OnStartData(ut);
            switch (CMD)
            { 
                case "New":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "增加分类信息";
                    Hidden_Disp();
                    break;
                case "List":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "查看分类信息";
                    Hidden_Input();
                    ButtonOption.Visible = false;
                    AddEditButton();
                    break;
                case "Edit":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "修改分类信息";
                    Hidden_Disp();
                    AddDeleteButton();
                    break;
                case "Delete":
                    
                    if(ut.Delete() > 0)
                    {
                        EventMessage.MessageBox(1, "删除成功", string.Format("删除ID:{0}成功!", IDX), Icon_Type.OK, Common.GetHomeBaseUrl("Default.aspx"));
                    }
                    else {
                        EventMessage.MessageBox(1, "删除失败", string.Format("删除ID:{0}失败!", IDX), Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
                    }
                    break;
                default :
                    EventMessage.MessageBox(2, "不存在操作字符串!", "不存在操作字符串!", Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
                    break;
            }
        }

        /// <summary>
        /// 增加修改按钮
        /// </summary>
        private void AddEditButton()
        {
            HeadMenuButtonItem bi = new HeadMenuButtonItem();
            bi.ButtonPopedom = NewLife.CommonEntity.PermissionFlags.Edit;
            bi.ButtonName = "分类信息";
            bi.ButtonUrl = string.Format("?CMD=Edit&IDX={0}", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi);
        }


        /// <summary>
        /// 增加删除按钮
        /// </summary>
        private void AddDeleteButton()
        {
            HeadMenuButtonItem bi = new HeadMenuButtonItem();
            bi.ButtonPopedom = NewLife.CommonEntity.PermissionFlags.Delete;
            bi.ButtonName = "分类信息";
            bi.ButtonUrlType = UrlType.JavaScript;
            bi.ButtonUrl = string.Format("DelData('?CMD=Delete&IDX={0}')", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi);

            HeadMenuButtonItem bi1 = new HeadMenuButtonItem();
            bi1.ButtonPopedom = NewLife.CommonEntity.PermissionFlags.List;
            bi1.ButtonIcon = "back.gif";
            bi1.ButtonName = "返回";
            bi1.ButtonUrl = string.Format("?CMD=List&IDX={0}", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi1);
        }

        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <param name="ut"></param>
        private void OnStartData(app_Category ut)
        {
        C_Name_Input.Text = C_Name_Disp.Text = ut.C_Name.ToString();
                C_Pinyin_Input.Text = C_Pinyin_Disp.Text = ut.C_Pinyin.ToString();
                C_ParentID_Input.Text = C_ParentID_Disp.Text = ut.C_ParentID.ToString();
                C_ShowOrder_Input.Text = C_ShowOrder_Disp.Text = ut.C_ShowOrder.ToString();
                C_Level_Input.Text = C_Level_Disp.Text = ut.C_Level.ToString();
                C_ChildCount_Input.Text = C_ChildCount_Disp.Text = ut.C_ChildCount.ToString();
                C_Attribute_Input.Text = C_Attribute_Disp.Text = ut.C_Attribute.ToString();
                C_Keyword_Input.Text = C_Keyword_Disp.Text = ut.C_Keyword.ToString();
                C_Description_Input.Text = C_Description_Disp.Text = ut.C_Description.ToString();
                
        }

        /// <summary>
        /// 隐藏输入框
        /// </summary>
        private void Hidden_Input()
        {
        C_Name_Input.Visible = false;
        C_Pinyin_Input.Visible = false;
        C_ParentID_Input.Visible = false;
        C_ShowOrder_Input.Visible = false;
        C_Level_Input.Visible = false;
        C_ChildCount_Input.Visible = false;
        C_Attribute_Input.Visible = false;
        C_Keyword_Input.Visible = false;
        C_Description_Input.Visible = false;
        
        }

        /// <summary>
        /// 隐藏显示框
        /// </summary>
        private void Hidden_Disp()
        {
        C_Name_Disp.Visible = false;
        C_Pinyin_Disp.Visible = false;
        C_ParentID_Disp.Visible = false;
        C_ShowOrder_Disp.Visible = false;
        C_Level_Disp.Visible = false;
        C_ChildCount_Disp.Visible = false;
        C_Attribute_Disp.Visible = false;
        C_Keyword_Disp.Visible = false;
        C_Description_Disp.Visible = false;
        
        }

        /// <summary>
        /// 增加/修改事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
        
            string C_Name_Value = (string)BingZi.HY.Core.Common.sink(C_Name_Input.UniqueID, MethodType.Post, 50, 1, DataType.Str);
            string C_Pinyin_Value = (string)BingZi.HY.Core.Common.sink(C_Pinyin_Input.UniqueID, MethodType.Post, 100, 1, DataType.Str);
            int C_ParentID_Value = (int)BingZi.HY.Core.Common.sink(C_ParentID_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            int C_ShowOrder_Value = (int)BingZi.HY.Core.Common.sink(C_ShowOrder_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            int C_Level_Value = (int)BingZi.HY.Core.Common.sink(C_Level_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            int C_ChildCount_Value = (int)BingZi.HY.Core.Common.sink(C_ChildCount_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            
            string C_Keyword_Value = (string)BingZi.HY.Core.Common.sink(C_Keyword_Input.UniqueID, MethodType.Post, 100, 0, DataType.Str);
            string C_Description_Value = (string)BingZi.HY.Core.Common.sink(C_Description_Input.UniqueID, MethodType.Post, 200, 0, DataType.Str);
            app_Category ut = app_Category.FindByKeyForEdit(IDX);
            
            ut.C_Name = C_Name_Value;
            ut.C_Pinyin = C_Pinyin_Value;
            ut.C_ParentID = C_ParentID_Value;
            ut.C_ShowOrder = C_ShowOrder_Value;
            ut.C_Level = C_Level_Value;
            ut.C_ChildCount = C_ChildCount_Value;
            //ut.C_Attribute = C_Attribute_Value;
            ut.C_Keyword = C_Keyword_Value;
            ut.C_Description = C_Description_Value;
            
            Int32 rInt =0; if (CMD == "New")
            {
                rInt = ut.Insert();
            }
            else if (CMD == "Edit")
            {
                rInt = ut.Update();
            }
            else
            {
                EventMessage.MessageBox(2, "不存在操作字符串!", "不存在操作字符串!", Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
            }
            
            if ( rInt> 0)
            {
                string OpTxt = string.Format("增加分类信息成功!(ID:{0})", rInt);
                if(CMD == "Edit")
                    OpTxt = string.Format("修改分类信息成功!(ID:{0})",IDX);
                EventMessage.MessageBox(1, "操作成功", OpTxt, Icon_Type.OK, Common.GetHomeBaseUrl("Default.aspx"));
            }
            else if (rInt == -2)
            {
                EventMessage.MessageBox(1, "操作失败", "操作失败,存在相同的键值(用户名/数据)!", Icon_Type.Alert, Common.GetHomeBaseUrl("Default.aspx"));
            }
            else
            {
                EventMessage.MessageBox(1, "操作失败", string.Format("操作失败,返回值:{0}!", rInt), Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
            }
        }
    }
}
